package com.makefriends.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.makefriends.R;
import com.makefriends.adapter.CommonPagerAdapter;
import com.makefriends.view.PagerSlidingTabStrip;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by sks on 2016/3/7.
 */
public class ThirdEmailFragment extends LazyFragment implements ViewPager.OnPageChangeListener {

    public static int CLASS_TYPE = 0;
    private View mView;

//    @Bind(R.id.email_viewpager)
    ViewPager mViewPager;

//    @Bind(R.id.email_tabs)
    PagerSlidingTabStrip tabs;
    private Activity mContext;
    private CommonPagerAdapter mAdapter;

    protected int mCurrentTab = 0;
    protected int mLastTab = -1;

    private final List<String> titles = new ArrayList<>();

    private List<Fragment> pages= new ArrayList<Fragment>();

    @Override
    protected void lazyLoad() {

    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        mContext = activity;
    }

    @Override
    protected View doCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_email,container,false);
//        ButterKnife.bind(mContext);
        mViewPager = (ViewPager) mView.findViewById(R.id.email_viewpager);
        tabs = (PagerSlidingTabStrip) mView.findViewById(R.id.email_tabs);

        //添加页卡视图
        pages.add(new EmailNoticFragment());
        pages.add(new EmailChatFragment());
        pages.add(new EmailRecentContactFragment());

        titles.add(mContext.getString(R.string.str_notification_title));
        titles.add(mContext.getString(R.string.str_personal_letter_title));
        titles.add(mContext.getString(R.string.str_recently_contact_title));

        mAdapter = new CommonPagerAdapter(getChildFragmentManager(), pages,titles);
        mViewPager.setAdapter(mAdapter);
        mViewPager.setCurrentItem(mCurrentTab);
        mLastTab = mCurrentTab;

        tabs.setViewPager(mViewPager);
        tabs.setOnPageChangeListener(this);

        return mView;
    }


    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        mCurrentTab = position;
        CLASS_TYPE = position;
    }

    @Override
    public void onPageScrollStateChanged(int state) {
        if (state == ViewPager.SCROLL_STATE_IDLE) {
            mLastTab = mCurrentTab;
        }
    }
}
